<template>
	<view class="info-content">
		<view class="info-box" v-for="(item,index) in list" :key='index' @click="queryDetail(item)">
			<view class="box-title" >
		<text class="bgcolor" >{{item.contractTypeDictText}}</text>
		<text>【{{item.contractCode}}】{{item.contractName}}</text>
			</view>
			<view class="box-footer">
				<view class="box-status" >
					<text style="margin-right: 20rpx;">{{item.approveStatusDictText}}</text>
					<text v-if="type === 'accept'" :class="[item.acceptanceResult === '0' ? 'text-orange' : 'text-cyan']">
					    <!-- {{item.processStatusDictText}} -->
					</text>

				</view>
				<view class="box-time">
					<text>{{item.createTime}}</text>
				</view>
			</view>
		</view>
		 <view class="info-box" style="border:none" v-if="list.length==0">
		 	<view class="box-nofooter" style="text-align: center;line-height: 50rpx;">
		 		没有搜索到数据！
		 	</view>
		 </view>
		 <view class="info-box" style="border:none" v-if="list.length>0" @click="loadMore">
		 	  <view class="box-nofooter" style="text-align: center;line-height: 50rpx;">
		 	  	{{total>list.length?'点击加载更多！':'已经到底了啦！'}}
		 	  </view>
		 </view>
		
	</view>
</template>

<script>
	import {getUserHTList,queryDictList,queryDictValue} from '../../api/service.js'
	export default{
		props:['type'],
		data(){
			return{
				list:[],
				total:0,
				url:{
					query:"contract/myContractsApp",
					// accept:'/tHtContract/AcceptancePageLists'
				},
				name:'',
				currentPageNo:1,
				queryParam:{
				pageNo:1,
				pageSize:10
				}
			}
		},
		
		created() {
			this.queryParam.pageNo=1,
			this.queryParam.pageSize=10;
			this.currentPageNo=1;
			this.getAppProInfo();
		},
		methods:{
			reloadList(data){
				this.queryParam.pageNo=1,
				this.queryParam.pageSize=10;
				this.currentPageNo=1;
				this.name=data.name;
				console.log('搜索名字'+this.name)
				this.getAppProInfo();
			},
			loadMore(){
				// 数据待到总数一致时候停止在加载
				if(this.list.length>=this.total){
					// uni.
				}else{
					this.currentPageNo++;
					this.queryParam.pageSize=this.currentPageNo*10
					this.getAppProInfo()
				}
			},
			queryDetail(item){
				uni.navigateTo({
					url:'../../component/queryContractDetail?id='+item.id+'&processId='+item.processId+'&status='+item.acceptanceResult+'&cgId='+item.cgId+"&type="+this.type
				})
			},
			async getAppProInfo(append = false) { // 添加一个参数 append，默认为 false
			  uni.showLoading({
			    title: '数据加载中'
			  });
			
			
			  this.isLoading = true;
			  try {
			    const res = await getUserHTList({
			      pageNo: this.queryParam.pageNo,
			      pageSize: this.queryParam.pageSize,
				  contractName: this.name
			    });
			
			    if (res.success) {
			      uni.hideLoading(); // 隐藏加载提示
			      this.total = res.result.total;
			      if (append) {
			        this.list = this.list.concat(res.result.records); // 将新数据追加到现有数据的末尾
			      } else {
			        this.list = res.result.records;
			      }
			    } else {
			      uni.showToast({
			        title: "数据加载失败！",
			        duration: 2000
			      });	
			    }
			  } catch (error) {
			    console.error("获取数据失败:", error);
			  } finally {
			    this.isLoading = false;
			  }
			},
			// code 的码装换
			blackCode(type, values) {
			    console.log('values: ' + values);
			    console.log('type: ' + type);
			    var tempDt = null;
			
			    return new Promise(function(resolve, reject) {
			        // 构建参数对象
			        const parameter = {
			            id: type,  // 将 values 作为 id
			            type: values  // 将 type 作为 type
			        };
			
			        // 调用 queryDictValue 并传递参数
			        queryDictValue(parameter).then(res => {
			            if (res.success) {
			                tempDt = res.result.filter(item => {
			                    return item.value == values;
			                });
			                resolve(tempDt.length > 0 ? tempDt[0].text : '--');
			            } else {
			                reject('--');
			            }
			        }).catch(error => {
			            // 处理请求错误
			            console.error('Error fetching dictionary value:', error);
			            reject('--');
			        });
			    });
			}

		}
	}
</script>

<style lang="scss">
	.info-content{
		width: 100%;
		height: auto;
		position: relative;
		background: #fff;
		.info-box{
			display: flex;
			flex-direction:column;
			justify-content: center;
			padding: 18rpx 22rpx;
			border-bottom: 2rpx solid #F7F4F4;
			.box-title{
				flex: 1;
				padding:12rpx 0rpx 10rpx;
				font-size:28rpx;
				font-family:PingFangSC-Regular,PingFang SC;
				font-weight:400;
				color:#333333;
				line-height: 40rpx;
				text{
					vertical-align: middle;
				}
				.bgcolor{
					background: #FDE7D2;
					color:#A07C5A;
					display: inline-block;
					padding: 0 10rpx;
					border-radius: 4rpx;
					font-size:22rpx;
					line-height: 32rpx;
					font-family:PingFangSC-Regular,PingFang SC;
					font-weight:400;
					text-align: center;
				}
			}
			.box-footer{
				display: flex;
				flex: 1;
				flex-direction: row;
				justify-content: flex-start;
				font-size:26rpx;
				font-family:PingFangSC-Regular,PingFang SC;
				font-weight:400;
				color:#999999;
				.box-status{
					flex: 1;
				}
				.box-time{
					flex: 1;
					text-align: right;
					font-size:22rpx;
				}
				
			}
		}
	}
</style>
